package com.yangl.study.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author yanglei
 * @date 2021-12-05 22:33
 */
public class TimerInterceptor implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        long time = System.currentTimeMillis();
        String methodName = invocation.getMethod().getName();
        System.out.println("Invocation of Method " + methodName + " start!");
        Object proceed = invocation.proceed();
        System.out.println("Invocation of Method " + methodName + " end! takes " + (System.currentTimeMillis() - time) + " nanoseconds.");
        return proceed;
    }
}
